/**
 * 
 */
package NewGW;

import java.io.File;

import org.apache.commons.net.tftp.TFTPDataPacket;

import utils.variable;

/***********
 * Class used to display TFTP Transfert progression
 */
public class displayTFTPProg extends Thread
	{
	/**
	 * Variables
	 */
	private TFTPServer ts;
	private boolean done;
	
	
	/**
	 * Constructeur
	 */
	public displayTFTPProg(TFTPServer ts)
		{
		this.ts=ts;
		done = true;
		
		//On fige le curseur
		variable.getaWindow().setTP();
		
		start();
		}
	
	public void run()
		{
		int len = 0;
		float percent = 0;
		while(done)
			{
			File fileG = new File(variable.getTftpDir()+"/"+ts.getFileName());
			if(fileG.exists())
				{
				len = (int)fileG.length()/TFTPDataPacket.MAX_DATA_LENGTH;
				percent = ((float)ts.getBlock()/(float)len)*100F;
				}
			
			variable.getaWindow().addInfoStatic("########## Transfert en cours : "+ts.getFileName()+"    Progression : "+(int)percent+"% ##########");
			try
				{
				this.sleep(100);
				}
			catch(Exception exc)
				{
				exc.printStackTrace();
				}
			}
		}
	
	
	public void shutdown()
		{
		done=false;
		}
	
	
	/*2012*//*RATEL Alexandre 8)*/
	}
